package charUtf8;

import java.io.UnsupportedEncodingException;

public class Main {

    public static void main(String[] args) {
        charLength('庆');
        charLength('a');
        charLength('￥');
        charLength('汉');

        utfLength("汉");
//        utfLength("中");
//        utfLength("￥");
//        utfLength("a");
    }

    private static void charLength(char c) {
        System.out.println(c + " --");
        System.out.println(Integer.toHexString(c));
    }

    private static void utfLength(String str) {
        System.out.println();
        System.out.println();
        try {
            System.out.println(str + " ------ Start");
            byte[] z = str.getBytes("utf-8");
            System.out.println(str + "utf-8 length " + z.length);

            for(byte b : z){
                System.out.print(Integer.toHexString(Byte.toUnsignedInt(b)));
                System.out.print(" ");
            }

            System.out.println();
            System.out.println();
            byte[] z2 = str.getBytes("utf-16");
            System.out.println(str + "utf-16 length " + z2.length);
            for(byte b : z2){
                System.out.print(Integer.toHexString(Byte.toUnsignedInt(b)));
                System.out.print(" ");
            }

            System.out.println();
            System.out.println();
            byte[] z3 = str.getBytes("utf-32");
            System.out.println(str + " utf-32 length " + z3.length);
            for(byte b : z3){
                System.out.print(Integer.toHexString(Byte.toUnsignedInt(b)));
                System.out.print(" ");
            }

            System.out.println(str + " ------ End");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
